local M = {}

--table转string
function M.table2string(t)
	local mark={}
	local assign={}

	local function ser_table(tbl,parent)
		mark[tbl]=parent
		local tmp={}
		for k, v in pairs(tbl) do
			local key= type(k)=="number" and "["..k.."]" or "[".. string.format("%q", k) .."]"
			if type(v)=="table" then
				local dotkey= parent .. key
				if mark[v] then
					table.insert(assign, dotkey .. "=" .. mark[v] .. "")
				else
					table.insert(tmp, key .. "=" .. ser_table(v,dotkey))
				end
			elseif type(v) == "string" then
				table.insert(tmp, key .. "=" .. string.format('%q', v))
			elseif type(v) == "number" or type(v) == "boolean" then
				table.insert(tmp, key .. "=" .. tostring(v))
			end
		end
		return "{" .. table.concat(tmp,",") .. "}"
	end

	return ser_table(t,"ret") .. table.concat(assign, "")
end

function M.size(t)
    local size = 0
    for _, _ in pairs(t or {}) do
        size = size + 1
    end

    return size
end

return M